package com.sentiment.crawler;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.sentiment.webcollector.crawler.DeepCrawler;
import com.sentiment.webcollector.model.Links;
import com.sentiment.webcollector.model.Page;

public class SohuRelativeCrawler extends DeepCrawler{

	public SohuRelativeCrawler(String crawlPath) {
		super(crawlPath);
		// TODO Auto-generated constructor stub
	}
	private List<String> list;
	@Override
	public Links visitAndGetNextLinks(Page page) {
		// TODO Auto-generated method stub
		Document doc = page.getDoc();
		Element ele = doc.getElementById("rs");
		Elements eles = ele.getElementsByTag("a");
		Iterator<Element> iter = eles.iterator();
		while(iter.hasNext()){
			String s = iter.next().text();
			list.add(s);
		}
		return null;
	}
	
	public List<String> getSearch(String keyword){
		list = new ArrayList<String>();
		try{
			addSeed("http://www.sohu.com/?word=" + URLEncoder.encode(keyword, "utf-8"));
			start(1);
			if(!list.isEmpty())
				return list;
		} catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
